$(function(){
	$("form[type='dataForm']").validate({
		submitHandler: function(form){
			var bo = true;
			//验证回调
			if(validateCallback&&typeof validateCallback == "function"){
				bo = validateCallback();
			}
			if(bo){
				var data = new FormData(form);
				var href = $(form).attr("dataHref");
				var url = baseUrl + href;
				console.log(url);
				$.ajax({
			        type: 'post',
			        url:url,
			        contentType: false,  
			        processData: false, 
			        async: false,
			        data:data
				}).done(function(dt){
					if(submitCallback&&typeof submitCallback == "function"){
						//提交回调
						submitCallback(dt);
					}else{
						parent.layer.closeAll();
						layer.closeAll();
						location.histroy.go(-1);
					}
				});
			}
		},
		errorContainer: "#messageBox",
		errorPlacement: function(error, element) {
			$("#messageBox").text("输入有误，请先更正。");
			if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
				error.appendTo(element.parent().parent());
			} if(element.is(":checkbox")||element.is(":radio")||element.parent().is(".vali-class")){
                error.appendTo(element.parent());
			} else {
				error.insertAfter(element);
			}
		}
	});
	$.fn.initForm = function(data){
		var $this = $(this);
		$.each(data, function(key, val) {
			$this.find("[name='" + key + "']").val(val);
		})
	};
    $.fn.initEmForm = function(data){
        var $this = $(this);
        $this.find('em').each(function () {
            var name = $(this).attr('name');
            $(this).text(data[name]);
        })
        $this.find('span').each(function () {
            var name = $(this).attr('name');
            $(this).text(data[name]);
        })
        $this.find('textarea').each(function () {
            var name = $(this).attr('name');
            $(this).val(data[name]);
        })
    };
})
